package com.qt.controller.oj;

import com.qt.annotation.OpenApi;
import com.qt.manager.oj.LoginManager;
import com.qt.pojo.dto.LoginDTO;
import com.qt.pojo.dto.PostResetPasswordDTO;
import com.qt.pojo.dto.RegisterDTO;
import com.qt.pojo.dto.ResetPasswordDTO;
import com.qt.result.R;
import com.qt.service.oj.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author pgw
 * @version 1.0
 * @description 处理登录、注册、重置密码
 * @date Create by 2023/9/18 12:10
 */
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;



    @PostMapping("/login")
    @OpenApi
    public R login(@Validated @RequestBody LoginDTO loginDTO , HttpServletRequest request  , HttpServletResponse response){
         return  loginService.login(loginDTO , request , response);
    }


    @PostMapping("/register")
    @OpenApi
    public  R register(@RequestBody RegisterDTO registerDTO){
       return  loginService.register(registerDTO);
    }


    @GetMapping("/register-code")
    @OpenApi
    public  R  getRegisterCode(@RequestParam(value = "email" , required = true) String email){
        return loginService.getRegisterCode(email);
    }


    @PostMapping("/reset-password")
    @OpenApi
    public  R resetPassword(@RequestBody ResetPasswordDTO resetPasswordDto){
        return  loginService.resetPassword(resetPasswordDto);
    }

    /**
     * 给指定邮箱发送重置密码消息链接
     * @param postResetPasswordDto
     * @return
     */
    @PostMapping("/reset-url-password")
    @OpenApi
     public  R postResetPassword(@RequestBody PostResetPasswordDTO postResetPasswordDto){
         return  loginService.postResetPassword(postResetPasswordDto);
    }

    @GetMapping("/logout")
    public void logout(){
       loginService.logout();
    }





}
